package com.asset.dispoal.business.bsCase.service.commom;

import com.asset.dispoal.business.bsCase.domain.db.entity.BsCase;
import com.asset.dispoal.business.bsCase.domain.db.mapper.BsCaseMapper;
import com.asset.dispoal.business.bsCase.dto.BsCaseResponse;
import com.asset.dispoal.business.bsCase.service.converter.BsCaseConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;

/**
 * @author qr
 * @date 2022/4/12$
 */
@Component
public class QueryCaseByIdCommand implements BaseCommand<String, Result<BsCaseResponse>> {


    @Autowired
    BsCaseMapper bsCaseMapper;

    @Override
    public Result<BsCaseResponse> execute(String caseId) {
        BsCase bsCase = bsCaseMapper.getCaseById(caseId);
        BsCaseResponse bsCaseResponse = BsCaseConverter.INSTANCE.caseToRes(bsCase);
        bsCaseResponse.setRecordResponseList(bsCaseMapper.queryStateRecordById(caseId));
        return Result.ok(bsCaseResponse);

    }
}
